package com.iss.umservice.manager.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iss.umservice.bean.AnnouncementBean;
import com.iss.umservice.bean.AnnouncementNoReadQueryBean;
import com.iss.umservice.bean.AnnouncementReadBean;
import com.iss.umservice.bean.AnnouncementReadedQueryBean;
import com.iss.umservice.bean.AnnouncementReadedResultBean;
import com.iss.umservice.bean.AnnouncementReadedResultSummaryBean;
import com.iss.umservice.bean.QueryAnnouncementBean;
import com.iss.umservice.dao.AnnouncementDao;
import com.iss.umservice.dao.AnnouncementreadDao;
import com.iss.umservice.manager.AnnouncementManager;

@Service
public class AnnouncementManagerImpl implements AnnouncementManager {
	private final Logger logger = LoggerFactory.getLogger(getClass());

	@Autowired
	private AnnouncementDao announcementDao;
	@Autowired
	private AnnouncementreadDao announcementreadDao;

	@Override
	public int addAnnouncement(AnnouncementBean newComp) {
		return announcementDao.addAnnouncement(newComp);
	}

	@Override
	public void modAnnouncement(AnnouncementBean ann) {
		announcementDao.modAnnouncement(ann);
	}

	@Override
	public void delAnnouncement(AnnouncementBean ann) {
		announcementDao.delAnnouncement(ann);
	}

	@Override
	public List<QueryAnnouncementBean> queryAnnouncements(
			QueryAnnouncementBean condition, int offset, int row) {
		return announcementDao.queryAnnouncements(condition, offset, row);
	}

	@Override
	public AnnouncementBean getAnnouncement(AnnouncementBean condition) {
		return announcementDao.getAnnouncement(condition);
	}

	@Override
	public List<QueryAnnouncementBean> allAnnouncement() {
		return announcementDao.allAnnouncement();
	}

	@Override
	public int countAnnouncement(QueryAnnouncementBean condition) {
		return announcementDao.countAnnouncement(condition);
	}

	@Override
	public void discardAnnouncement(int[] ids) {
		for (int id : ids) {
			announcementDao.discardAnnouncement(id);
		}
	}

	@Override
	public List<AnnouncementNoReadQueryBean> queryNoReadAnn(String currUserId,
			int offset, int row) {
		return announcementreadDao.queryNoReadAnn(currUserId, offset, row);
	}

	@Override
	public List<AnnouncementReadedQueryBean> queryReadedAnn(String currUserId,
			int offset, int row) {
		return announcementreadDao.queryReadedAnn(currUserId, offset, row);
	}

	@Override
	public int countNoReadAnn(String currUserId) {
		return announcementreadDao.countNoReadAnn(currUserId);
	}

	@Override
	public int countReadedAnn(String currUserId) {
		return announcementreadDao.countReadedAnn(currUserId);
	}

	@Override
	public void readedAnn(int annId, String currUserId, String receiptMsg,
			Integer receiptSelectionId) {
		AnnouncementReadBean newReadAnn = new AnnouncementReadBean();
		newReadAnn.setUserid(currUserId);
		newReadAnn.setAnnid(annId);
		newReadAnn.setReceiptmsg(receiptMsg);
		newReadAnn.setReceiptitemid(receiptSelectionId);
		announcementreadDao.addReadedAnn(newReadAnn);
	}

	@Override
	public AnnouncementReadBean getReadedAnn(int annId, String currUserId) {
		return announcementreadDao.getReadedAnn(annId, currUserId);
	}

	@Override
	public List<AnnouncementReadedResultBean> queryReadedAnnResult(
			AnnouncementReadedResultBean bean, int offset, int row) {
		return announcementreadDao.queryReadedAnnResult(bean, offset, row);
	}

	@Override
	public int countReadedAnnResult(AnnouncementReadedResultBean bean) {
		return announcementreadDao.countReadedAnnResult(bean);
	}

	@Override
	public List<AnnouncementReadedResultSummaryBean> queryReadedAnnResultSummary(AnnouncementReadedResultSummaryBean bean) {
		return announcementreadDao.queryReadedAnnResultSummary(bean);
	}
}
